package org.shijiagen.collect.controller;

import lombok.RequiredArgsConstructor;
import org.shijiagen.collect.service.CollectService;
import org.shijiagen.pojo.Collect;
import org.shijiagen.utils.R;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("collect")
@RequiredArgsConstructor
public class CollectController {

    private final CollectService collectService;

    @PostMapping("list")
    public R list(@RequestBody Collect collect){
        return R.ok(collectService.list(collect.getUserId()));
    }

    @PostMapping("save")
    public R save(@RequestBody Collect collect){
        return collectService.save(collect) ? R.ok("收藏添加成功") : R.fail("收藏添加失败");
    }

    @PostMapping("remove")
    public R remove(@RequestBody Collect collect){
        return collectService.remove(collect) ? R.ok("删除成功") : R.fail("删除失败");
    }

    @PostMapping("remove/product")
    public R removeByPid(@RequestBody Integer productId){
        return collectService.removeByPid(productId) ? R.ok("删除成功") : R.ok("没有删除的商品");
    }
}
